package com.lagou.boot;

import com.lagou.client.RPCConsumer;
import com.lagou.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Component
public class ConsumerBoot implements ApplicationRunner {

    @Autowired
    private RPCConsumer rpcConsumer;

    @Override
    public void run(ApplicationArguments args) {
        //1.创建代理对象
        IUserService service = (IUserService) rpcConsumer.createProxy(IUserService.class);

        try {
            //2.循环给服务器写数据
            while (true){
                String result = service.sayHello("Hello Provider~！");
                System.out.println(result);
                Thread.sleep(2000);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
